<!DOCTYPE html>
<html>
<head lang="en">
    <meta name="viewport" content="width=device-width;initial-scale=1.0">
    <meta charset="UTF-8">
    <title></title>
    <script src="./jquery-2.1.1.js"></script>
</head>
<body>
<input type="text" id="all_text"/>
<input type="text" id="msg"/>
<input type="button" value="send" id="send"/>


<script type="text/javascript">
    window.WebSocket = window.WebSocket || window.MozWebSocket;
    var allText = $('#all_text');
    var conn = new WebSocket('ws://localhost:3000');
    conn.onopen = function () {
        console.log('onopen');
        //TODO
    };

    conn.onerror = function (err) {
        console.log('onerror');
        //TODO
    };

    conn.onmessage = function (msg) {
        console.log('msg', msg);
        //TODO
        var preText = allText.val();
        allText.val(preText + "\n" + msg);
    };


    $('#send').click(function () {
        console.log('send');
        var msg = $('#msg').val();
        conn.send(msg);
        var preText = allText.val();
        allText.val(preText + "\n" + msg);

    })
</script>
</body>
</html>